package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
@Reference
    private MenuService menuService;
//查询所有菜单信息
    @RequestMapping("/findAll")
    public Result findAll(){
        try {
         List<Menu> data = menuService.findAll();
            return new Result(true,MessageConstant.QUERY_MENU_SUCCESS,data);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_MENU_FAIL);
        }
    }

    @RequestMapping("/findMenuIdsByRoleId")
    //根据角色id查询对应菜单id
    public Result findMenuIdsByRoleId(Integer roleId){
        try{
           List<Integer> list = menuService.findMenuIdsByRoleId(roleId);
            return new Result(true,MessageConstant.QUERY_MENU_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_MENU_FAIL);

        }

    }

}
